import { defineStore } from "pinia";
import request from "@/utils/request";
import { CategoryItem, IApiRes,TopCategory } from "@/types/data";
import { topCategory } from '../constants'
const topCategoryList = topCategory.map(it => ({id:it,name: it}))
export default defineStore("category", {
  state() {
    return {
      topCategory: {} as TopCategory,
      list: [] as CategoryItem[] 
    };
  },
  actions: {
    async getCategoryList() {
      const res = await request.get<IApiRes<CategoryItem[]>>("/home/category/head");
      console.log(res);
      this.list = res.data.result
    },
        // 获取一级类目的信息
        async getTopCategory(id: string){
          // const res = await request.get<{msg: string, result:CategoryItem[]}>('/home/category/head')
          const res = await request.get<IApiRes<TopCategory>>('/category', {
            params: {id: id}
          })
          
          console.log('getTopCategory', res)
          this.topCategory = res.data.result
        },
  },
  persist: {
    enabled:true,
    strategies:[{key:'abc'}]
    // key:'category'
  }
});


const a = {
  "id": "1005000",
  "name": "居家",
  "picture": "http://yjy-xiaotuxian-dev.oss-cn-beijing.aliyuncs.com/picture/2021-05-06/201516e3-25d0-48f5-bcee-7f0cafb14176.png",
  "children": [
    {
      "id": "1005009",
      "name": "茶咖酒具",
      "picture": "https://yanxuan.nosdn.127.net/3102b963e7a3c74b9d2ae90e4380da65.png?quality=95&imageView",
      "children": null,
      "goods": null
    },
    {
      "id": "1007000",
      "name": "水具杯壶",
      "picture": "https://yanxuan.nosdn.127.net/45b50d5f8afbd6fdef97314647dcb7db.png?quality=95&imageView",
      "children": null,
      "goods": null
    },
    {
      "id": "1017000",
      "name": "宠物食品",
      "picture": "https://yanxuan.nosdn.127.net/b42a85ef15f856081ea9f49e5f6893e2.png?quality=95&imageView",
      "children": null,
      "goods": null
    },
    {
      "id": "109248004",
      "name": "宠物用品",
      "picture": "https://yanxuan.nosdn.127.net/e766b09029ca00680d1e651b5cdc42bd.png?quality=95&imageView",
      "children": null,
      "goods": null
    }
  ],
  "goods": [
    {
      "id": "1028010",
      "name": "圆润大肚流线型耐热玻璃凉水壶",
      "desc": "1.25L容量，耐冷耐热，通透好用",
      "price": "79.00",
      "picture": "https://yanxuan-item.nosdn.127.net/235326170a18f9b220a10928208336c5.png",
      "discount": null,
      "orderNum": null
    },
    {
      "id": "1035005",
      "name": "不烫手的茶杯双层隔热茶水杯绿茶杯",
      "desc": "360°赏茶汤，100℃不烫手",
      "price": "49.00",
      "picture": "https://yanxuan-item.nosdn.127.net/a67e6f85a4fc128ab3a2efad5279ca15.png",
      "discount": null,
      "orderNum": null
    },
    {
      "id": "1037001",
      "name": "热销30w+清洗不用愁简约陶瓷马克杯",
      "desc": "优质炫瓷，不易留渍",
      "price": "19.90",
      "picture": "https://yanxuan-item.nosdn.127.net/f356d90bcf6443a95bc44a039a0b26b0.png",
      "discount": null,
      "orderNum": null
    },
    {
      "id": "1039037",
      "name": "匠心手工羊脂玉白茶具礼盒6件套",
      "desc": "礼盒套装，送礼佳品",
      "price": "339.00",
      "picture": "https://yanxuan-item.nosdn.127.net/9208f2df07d79dd39fb9f5eaf9ca95c6.png",
      "discount": null,
      "orderNum": null
    },
    {
      "id": "1109023",
      "name": "真空红酒瓶塞带计时功能升级款",
      "desc": "保鲜浪漫，留住口感",
      "price": "29.90",
      "picture": "https://yanxuan-item.nosdn.127.net/4a9f4a6deefc5f3ea9f0456fe197a4d4.jpg",
      "discount": null,
      "orderNum": null
    },
    {
      "id": "1145018",
      "name": "喝水也要好心情日本美浓烧和蓝系列马克杯",
      "desc": "妙趣横生，经久耐用",
      "price": "55.00",
      "picture": "https://yanxuan-item.nosdn.127.net/f6227a607e93db11b2d4c307aa2dc370.png",
      "discount": null,
      "orderNum": null
    },
    {
      "id": "1146000",
      "name": "让全家人喝上甜甜的水黑科技镁离子净水壶",
      "desc": "德国净水黑科技，3.3L大容量",
      "price": "178.00",
      "picture": "https://yanxuan-item.nosdn.127.net/c09706c1e85dd2f5c9886b4f3e0cbbf0.png",
      "discount": null,
      "orderNum": null
    },
    {
      "id": "1146001",
      "name": "四重过滤添加矿物质镁离子滤芯",
      "desc": "补充镁离子，改善口感",
      "price": "169.00",
      "picture": "https://yanxuan-item.nosdn.127.net/36cecf28c2cf52c59632e81ca8d59234.png",
      "discount": null,
      "orderNum": null
    },
    {
      "id": "1318002",
      "name": "每一口都有七种肉，全价猫粮1.8千克",
      "desc": "多肉零谷物，升级低便臭配方",
      "price": "9.90",
      "picture": "https://yanxuan-item.nosdn.127.net/c7624da2f7763bbdf275ed09c1aa58de.jpg",
      "discount": null,
      "orderNum": null
    }
  ]
}
